//
//  RTJInvitationController.m
//  RuiTaiJinProject
//
//  Created by jayson on 2018/12/11.
//  Copyright © 2018年 leewei. All rights reserved.
//

#import "RTJInvitationController.h"
#import "RTJInvestmentRootController.h"

@interface RTJInvitationController ()
@property (weak, nonatomic) IBOutlet UILabel *peopleNum;
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (nonatomic,strong) NSDictionary *data;
@property (weak, nonatomic) IBOutlet UIView *bg_view;
@property (weak, nonatomic) IBOutlet UIView *bg_view2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewTop;

@end

@implementation RTJInvitationController

-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
     self.viewTop.constant = screenH == 812 ? 88 : 64;
    // Do any additional setup after loading the view from its nib.
    self.title = @"我的邀请";
//     self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_fenxiang"] style:UIBarButtonItemStylePlain target:self action:@selector(share)];
    
    [self backview:_bg_view viewOfcornerRadius:5];
    [self backview:_bg_view2 viewOfcornerRadius:5];
    
    [self loadData];
    
}

-(void)loadData{
    
    
    [SVProgressHUD  showWithStatus:nil];
    [self.view showEmptyViewWithStr:@"" image:nil callback:nil];
    [RTJNetWork asyncRequestWithURL:@"user/invite" params:nil method:GET zxCompletion:^(id data, NSInteger status, BOOL success, NSString *errorMsg) {
        
        [SVProgressHUD dismiss];
        [self.view removeEmptyView];

        if (success) {
            
            if ([data[@"status"]integerValue] == 1) {
                
                self.data = data[@"data"];
                self.peopleNum.text = [NSString stringWithFormat:@"%@人",data[@"data"][@"referral_user"]];
//                self.moneyLab.text = [NSString stringWithFormat:@"%@元",data[@"data"][@"total_referral_money"]];
                
                NSString *imgStr = [NSString stringWithFormat:@"%@%@",IMGURL,data[@"data"][@"share_url_img"]];
                NSString* encodedString = [imgStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [self.img  sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", encodedString]] placeholderImage:[UIImage imageNamed:@"kbylogo"]];
                
                NSString *shareUrl = [NSString stringWithFormat:@"%@",data[@"data"][@"share_url"]];
                shareUrl = [shareUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                
                
            }else{
                
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",data[@"msg"]]];
                [self.view showEmptyViewWithStr:data[@"msg"] image:[UIImage imageNamed:@"kbylogo"] callback:^{
                    [self loadData];
                }];
            }
            
        }else{
            
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",errorMsg]];
            [self.view showEmptyViewWithStr:errorMsg image:[UIImage imageNamed:@"kbylogo"] callback:^{
                [self loadData];
            }];
        }
        
    }];
}

-(void)backview:(UIView *)backview viewOfcornerRadius:(NSInteger)cornerRadius{
    
    backview.layer.cornerRadius = cornerRadius;
    backview.layer.shadowColor = [UIColor colorForHex:@"#dbc9cc"].CGColor;
    backview.layer.shadowOffset = CGSizeMake(-1, 1);
    backview.layer.shadowOpacity = 0.5;
    backview.layer.shadowRadius = 5;
    
}

-(void)share{
    
    
    
}

- (IBAction)invitation:(id)sender {

    RTJInvestmentRootController *vc = [[RTJInvestmentRootController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
